package cn.itsource.autoconfigure;

import cn.itsource.config.SaTokenConfigure;
import cn.itsource.config.StpInterfaceImpl;
import cn.itsource.interceptor.TokenInterceptor;
import cn.itsource.proterties.AuthProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

//自动配置
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties({AuthProperties.class})
public class AuthAutoConfiguration {
    //SaToken 拦截器配置
    @Bean
    public SaTokenConfigure saTokenConfigure(AuthProperties properties){
        return new SaTokenConfigure(properties);
    }

    //加载权限的接口
    @Bean
    public StpInterfaceImpl stpInterfaceImpl(RedisTemplate<Object,Object> redisTemplate){
        return new StpInterfaceImpl(redisTemplate);
    }

    //Token转发拦截器
    @Bean
    public TokenInterceptor tokenInterceptor(){
        return new TokenInterceptor();
    }

    /*密码加密器*/
    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    /*密码测试*/
    public static void main(String[] args) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        System.out.println(encoder.encode("123456"));

    }
}
